package com.progress.web;

import com.progress.pojo.Brand;
import com.progress.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static java.lang.Integer.parseInt;

@WebServlet("/updateServlet")
public class UpdateServlet extends HttpServlet {

    private BrandService brandService=new BrandService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");

        String id=request.getParameter("id");
        String brandName=request.getParameter("brandName");
        String companyName=request.getParameter("companyName");
        String ordered=request.getParameter("ordered");
        String description=request.getParameter("description");
        String status=request.getParameter("status");



        Brand brand=new Brand();
        brand.setId(Integer.valueOf(id));
        brand.setBrandName(brandName);
        brand.setCompanyName(companyName);
        brand.setOrdered(parseInt(ordered));
        brand.setDescription(description);
        brand.setStatus(parseInt(status));

        System.out.print(brand);

        brandService.update(brand);


        request.getRequestDispatcher("/selectAllServlet").forward(request,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
